package com.wennimei.service;

import org.springframework.stereotype.Service;

import com.wennimei.enums.MessageTypeEnum;

@Service
public class MessageTypeService {

    public MessageTypeEnum getMessageType(String content, String fromUserName) {
        if (null != content) {
            content = content.trim();
            if (content.equalsIgnoreCase("h")
                    || content.matches(MessageTypeEnum.HELP.getMatchRegx()))
                return MessageTypeEnum.HELP;
            else if (content.matches(MessageTypeEnum.EXPRESS.getMatchRegx())
                    && ExpressService.isExpress(content))
                return MessageTypeEnum.EXPRESS;
            else if (StarMatchService.isStarMatch(content))
                return MessageTypeEnum.STAR_MATCH;
            else if (content.matches(".*(怎么样|好玩|攻略).*")
                    && CityTourService.isCityTour(content))
                return MessageTypeEnum.CITY_TOUR;
            else {
                MessageTypeEnum[] enums = MessageTypeEnum.values();
                for (MessageTypeEnum e: enums) {
                    if (e.isSpecial())
                        continue;
                    if (content.matches(e.getMatchRegx()))
                        return e;
                }
            }
        } else {
            return MessageTypeEnum.DIANPING;
        }

        return MessageTypeEnum.CHAT;
    }

    public static void main(String[] args) {
        System.out.println("CA1861".matches(".*^[0-9a-zA-Z]{1,2}\\d{3,4}.*"));
    }
}
